import { useMemo } from 'react';
import { useRequest } from 'umi';
import { ILoadMapTypeAll } from '@/common';
import { getSelectDataCommon, getTenantID } from '@/utils';
import { adminAreadDataGet, loadMdicMap } from '@/services/BaseLayout';

export const ExpertsDictionaryService = () => {
  /**  专家库数据字典 */
  const loadMdicIds: string[] = [
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_TYPE}`,
    `${getTenantID()}${ILoadMapTypeAll.EDUCATION_LEVEL}`,
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_LEVEL}`,
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_CARD_TYPE}`,
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_ATTACH_TYPE}`,
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_INDUSTRY_TYPE}`,
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_CANCEL_TYPE}`,
    `${getTenantID()}${ILoadMapTypeAll.NATION_TYPE}`,
    `${getTenantID()}${ILoadMapTypeAll.POLITICAL_OUTLOOK}`,
    `${getTenantID()}${ILoadMapTypeAll.TALENT_TITLE}`,
    `${getTenantID()}${ILoadMapTypeAll.OVERSEAS_EXPERIENCE}`,
    `${getTenantID()}${ILoadMapTypeAll.PROFESSIONAL_LIST}`,
  ];

  /** 获取数据字典loadMdicMapList */
  const loadMdicMapList = useRequest(() => {
    return loadMdicMap(loadMdicIds);
  });

  /**获取省市区数据 */
  const areaList = useRequest(() => {
    return adminAreadDataGet({});
  });

  /**行政区域数据 */
  let areaListData = useMemo(() => {
    if (areaList?.data?.msgFlag) {
      return areaList?.data?.obj;
    } else {
      return [];
    }
  }, [areaList?.data]);

  /**字典数据 */
  let dictionaryData = useMemo(() => {
    if (loadMdicMapList?.data?.msgFlag) {
      return loadMdicMapList?.data?.obj;
    } else {
      return [];
    }
  }, [loadMdicMapList?.data]);

  // 专家类型
  const expertsTypeList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_TYPE}`], 'name', 'id');
  // 最高学历
  const educateLevelList: any = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.EDUCATION_LEVEL}`], 'name', 'id');
  // 专家级别
  const expertLevelList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_LEVEL}`], 'name', 'id');
  // 证件类型
  const cardTypeList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_CARD_TYPE}`], 'name', 'id');
  // 证书类型
  const attachTypeList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_ATTACH_TYPE}`], 'name', 'id');
  // 从事专业
  const industryTypeList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_INDUSTRY_TYPE}`], 'name', 'id');
  // 专家作废类型
  const cancelTypeList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_CANCEL_TYPE}`], 'name', 'id');
  // 民族
  const antionTypeList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.NATION_TYPE}`], 'name', 'id');
  // 政治面貌
  const politicalTypeList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.POLITICAL_OUTLOOK}`], 'name', 'id');
  // 人才称号
  const talentTitleList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.TALENT_TITLE}`], 'name', 'id');
  // 海外经历
  const overseasExperienceList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.OVERSEAS_EXPERIENCE}`], 'name', 'id');
  // 职称
  const professionalList = getSelectDataCommon(dictionaryData?.[`${getTenantID()}${ILoadMapTypeAll.PROFESSIONAL_LIST}`], 'name', 'id');

  return {
    areaListData,
    expertsTypeList,
    educateLevelList,
    expertLevelList,
    cardTypeList,
    attachTypeList,
    industryTypeList,
    cancelTypeList,
    antionTypeList,
    politicalTypeList,
    talentTitleList,
    overseasExperienceList,
    professionalList,
  };
};
